package thread;

import java.util.concurrent.CountDownLatch;

/**
 * Created by zhangmingbo on 1/7/17.
 */
public class Worker implements Runnable {


    private CountDownLatch countDownLatch;

    public Worker(CountDownLatch countDownLatch) {


        this.countDownLatch = countDownLatch;
    }

    public void run() {


        try {
            while (countDownLatch.getCount() > 0) {

                //do work
                TestUtil.doWorkByTime(Constants.WORK_TIME_MILLISECOND);

                //do block operation
                TestUtil.doBlockOperation(Constants.BLOCK_TIME_MILLISECOND);

                countDownLatch.countDown();
            }
        } catch (InterruptedException e) {
        }

    }
}
